package org.record.mood.common;


import com.alibaba.fastjson.annotation.JSONField;
import lombok.*;

import java.io.Serializable;

/**
 * @description:
 * @author: sunyw
 * @time: 2020-03-30 10:51
 */
@Data
public class CommonResp<T> implements Serializable {
    private Integer code;
    private String message;
    @JSONField
    private T data;
    private boolean success;

    /**
     * 错误请求
     * @param message
     * @return
     */
    public static synchronized CommonResp error(String message){
        CommonResp commonResp =new CommonResp();
        commonResp.setCode(CommonEnum.BAD_ERROR.getCode());
        commonResp.setSuccess(CommonEnum.Success.FALSE);
        commonResp.setMessage(message);
        return commonResp;
    }
    /**
     * 错误请求
     * @return
     */
    public static synchronized CommonResp error(){
        CommonResp commonResp =new CommonResp();
        commonResp.setCode(CommonEnum.BAD_ERROR.getCode());
        commonResp.setMessage(CommonEnum.BAD_ERROR.getMessage());
        commonResp.setSuccess(CommonEnum.Success.FALSE);
        return commonResp;
    }
    /**
     * 成功请求
     * @param message
     * @return
     */
    public static synchronized CommonResp success(String message, Object data){
        CommonResp commonResp =new CommonResp();
        commonResp.setCode(CommonEnum.SUCCESS.getCode());
        commonResp.setMessage(message);
        commonResp.setSuccess(CommonEnum.Success.SUCCESS);
        commonResp.setData(data);
        return commonResp;
    }
    /**
     * 成功请求
     * @return
     */
    public static synchronized CommonResp success(Object data){
        CommonResp commonResp =new CommonResp();
        commonResp.setCode(CommonEnum.SUCCESS.getCode());
        commonResp.setMessage(CommonEnum.SUCCESS.getMessage());
        commonResp.setSuccess(CommonEnum.Success.SUCCESS);
        commonResp.setData(data);
        return commonResp;
    }
}
